/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package control;

import com.opensymphony.xwork2.ActionSupport;

import java.util.List;
import pojo.Category;
import pojo.Thread;
import service.ICategoryService;
import service.IThreadService;
/**
 *
 * @author administrator
 */
public class CategoryAction extends ActionSupport{
    private ICategoryService<Category> categoryService;
    private IThreadService<Thread> threadService;
    private List<Category> categories;

    public IThreadService<Thread> getThreadService() {
        return threadService;
    }

    public void setThreadService(IThreadService<Thread> threadService) {
        this.threadService = threadService;
    }


    public List<Category> getCategories() {
        return categories;
    }

    public void setCategories(List<Category> categories) {
        this.categories = categories;
    }

    public ICategoryService<Category> getCategoryService() {
        return categoryService;
    }

    public void setCategoryService(ICategoryService<Category> categoryService) {
        this.categoryService = categoryService;
    }
   
    @Override
    public String execute()
    {
        this.categories = this.categoryService.listCategory();
        for(int i = 0;i<categories.size();i++)
        {
            int categoryID = this.categories.get(i).getCategoryId();
            Thread last = this.threadService.GetLastThread(categoryID);
            this.categories.get(i).setLastThread(last);
        }
        return "main";
    }

}
